package com.libgdxbar.pvzlikegame.screens.gamescreens;

import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ScreenUtils;
import com.libgdxbar.pvzlikegame.AssetsLoader;
import com.libgdxbar.pvzlikegame.entities.EntityGroup;
import com.libgdxbar.pvzlikegame.objects.*;
import com.libgdxbar.pvzlikegame.screens.GameScreenAdapter;
import com.libgdxbar.pvzlikegame.screens.screenkeys.ExampleScreenKey;
import com.libgdxbar.pvzlikegame.screens.screenkeys.ScreenKey;
import org.libgdxbar.projects.interfaces.Collisionable;

public class ShapeAndTextureEntityScreen extends GameScreenAdapter {
	Array<Collisionable> zombies;

	@Override
	public ScreenKey getScreenKey() {
		return ExampleScreenKey.ShapeAndTextureEntityExample;
	}

	protected void initViewport() {
		setViewport(640, 480);
	}

	@Override
	public void create() {
		// 这样创建实体 示例植物和示例僵尸都是实体
		new SampleShapePlant(100, 100);
		new SampleShapePlant(100, 200);
		new SampleTexturePlant(200, 100);
		new SampleTexturePlant(200, 200);
		new SampleTextureZombie(400, 300);
		new SampleTextureZombie(400, 400);
		new SampleTextureAsync(500, 500);
		zombies = new Array<>(new Collisionable[]{
			new SampleShapeZombie(300, 300),
			new SampleShapeZombie(300, 400),
			new SampleShapeZombie(400, 300),
			new SampleShapeZombie(400, 400),
			new SampleShapeZombie(500, 500),
			new SampleShapeZombie(300, 300),
			new SampleShapeZombie(300, 400),
			new SampleShapeZombie(400, 300),
			new SampleShapeZombie(400, 400),
			new SampleShapeZombie(500, 500),
		});
		zombies.forEach(e -> ((SampleShapeZombie) e).setCollisionEntities(zombies));
	}

	@Override
	public void render(float delta) {
		ScreenUtils.clear(0f, 0f, 0f, 1f);
		EntityGroup entities = EntityGroup.getInstance();
		entities.update(delta);
		entities.render(getViewport().getCamera());
	}

	@Override
	public void dispose() {
		EntityGroup.getInstance().dispose();
		AssetsLoader.getInstance().dispose();
	}
}
